import express from "express";
import { Server } from '@colyseus/core';
import { createServer } from "http";
import { WebSocketTransport } from "@colyseus/ws-transport";
import { GameRoom } from './gameRoom';
import { MMO_ROOM_NAME } from '../common';


const app = express();

const gameServer = new Server({
    transport: new WebSocketTransport({
        server: createServer(app)
    })
});

const port = process.env.PORT || 2567;
const host = '0.0.0.0';

gameServer.define(MMO_ROOM_NAME.GALLERY, GameRoom);
gameServer.listen(port as number, host, undefined, () => {
    const serverAddress = `http://${host === '0.0.0.0' ? 'localhost' : host}:${port}`;
    console.log(`server is running on ${serverAddress}`);
});

app.get('/', (req: any, res: any) => {
    res.send('colyseus server is running');
});